package app;

import service.*;
import entity.CarBusiness;
import util.ConverterTool;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.function.Function;

public class App {

    public static void main (String[] args){
        //start();
        new ViewInit();
    }

    private static void start(){
        System.out.println("请选择要导入的数据类型：1、房贷单 2、车贷单");
        Scanner scanner=new Scanner(System.in);
        try {
            String strType=scanner.nextLine();
            int type=ConverterTool.parseInt(strType);
            if(type==2 || type==1){
                System.out.println("请输入导入的excel路径：");
                String excel = scanner.nextLine();
                String sql = "";
                if(new CarService().dataType()==type){
                    sql = new CarService().importExcel(excel);
                }
                if(new HouseService().dataType()==type){
                    sql=new HouseService().importExcel(excel);
                }
                System.out.println("请输入生成的SQL路径：");
                String savePath = scanner.nextLine();
                if(FileService.saveFile(savePath,sql)){
                    System.out.println("生成成功！");
                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }finally {
            judge();
        }
    }

    private static void judge(){
        System.out.println("是否要再来？1、是");
        Scanner scanner=new Scanner(System.in);
        String strType=scanner.nextLine();
        int type=ConverterTool.parseInt(strType);
        if(type==1){
            start();
        }else {
            System.exit(0);
        }
    }
}
